#include "soaCarFileUpload.h"

#include "Basc_CarFileUpload.pb.h"
#include "data_build.h"

using namespace DcAdr;

SoaCarFileUpload::SoaCarFileUpload()
{

}

SoaCarFileUpload::~SoaCarFileUpload()
{

}

SoaCarFileUpload &SoaCarFileUpload::getInstance()
{
    static SoaCarFileUpload instance;
    return instance;
}

// adr-Soa.PB_Basc_CarFileUpload_Cnr_FileUpload_C2_In
void SoaCarFileUpload::Cnr_FileUpload_C2(const std::string &topic, const std::string &requestData, std::string &replyData)
{
    Log_Info("[SoaCarFileUpload][Cnr_FileUpload_C2] trigger");

    // RPC request
    Soa::PB_Basc_CarFileUpload_Cnr_FileUpload_C2_In carFileUploadIn;
    if (!carFileUploadIn.ParsePartialFromString(requestData))
    {
        Log_ERROR("[SoaCarFileUpload][Cnr_FileUpload_C2] parse proto data failed , topic: {}", topic);
    }

    Soa::PB_DC_FileList_Struct fileList = carFileUploadIn.filelist();
    std::string eventcode = carFileUploadIn.eventcode();
    try
    {
        /* code */
        DataBuild::DataCollectUpload_send(fileList, eventcode);
    }
    catch(const std::exception& e)
    {
        Log_Info("gd Exception occurred4 : {}", e.what());
        throw;
    }

    
    // RPC reply
    Soa::PB_Basc_CarFileUpload_Cnr_FileUpload_C2_Out carFileUploadOut;
    carFileUploadOut.set_return_(0);
    carFileUploadOut.SerializePartialToString(&replyData);
}